#include <sdfs/tracker/TrackerServer.h>
#include <sdfs/tracker/ConfigServer.h>
#include <sdfs/tracker/StatusServer.h>
#include <sdfs/config/TrackerConfig.h>

#include <stdio.h>
#include <muduo/base/Logging.h>
#include <muduo/base/LogFile.h>
#include <muduo/base/Types.h>

using namespace muduo;
using namespace sdfs::tracker;

boost::scoped_ptr<muduo::LogFile> g_logFile;

void logOutput(const char* msg, int len)
{
	g_logFile->append(msg, len);
}

int main(int argc, char* argv[])
{
//	g_logFile.reset(new muduo::LogFile(::basename("tracker"),500*1000*1000, true));
//	muduo::Logger::setOutput(logOutput);

	LOG_INFO << "PID = "<< getpid() << ", tid = "<< CurrentThread::tid();
	if(argc > 1)
		sdfs::TrackerConfig::setConfigFilename(argv[1]);
	else
		sdfs::TrackerConfig::setConfigFilename("tracker.conf");
	sdfs::TrackerConfig& conf = sdfs::TrackerConfig::getInstance();
	EventLoop loop;
	InetAddress listenAddr(conf.port());
	InetAddress confAddr(conf.confPort());
	InetAddress backendAddr(conf.storagePort());
	TrackerServer server(&loop, listenAddr, conf.threadNum());
	ConfigServer confSever(&loop, confAddr);
	StatusServer statusServer(&loop, backendAddr);
	server.start();
	confSever.start();
	statusServer.start();
	loop.loop();
}
